<h1>Create User</h1>

<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
    'id'=>'user-form',
    'enableAjaxValidation'=>false,
)); ?>


    <p class="help-block">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <fieldset>
    <legend>Project</legend>

    <?php echo $form->dropDownListRow($userProjectModel, 'project_id',
      CHtml::listData(Project::model()->findAll(), 'id', 'name'), array(
        'empty'=>'select Type',
        'ajax' => array(
          'type'=>'POST',
          'url'=>CController::createUrl(Yii::app()->language . '/projectNationality/getOptionByProjectId'),
          'data'=>array('projectId'=>'js:this.value'),
          'beforeSend' => "function(jqXHR, settings)
          {
              $('#" . CHtml::activeId($userProjectModel, 'nationality_id') . "')
                  .attr('disabled', 'disabled')
                  .find('option').remove();
          }",
          'success' => "function(data)
          {
              if(data.length > 0) {
                  $('#" . CHtml::activeId($userProjectModel, 'nationality_id') . "')
                      .removeAttr('disabled')
                      .append(data);
              }
          }",
         ))); ?>

    <?php echo CHtml::label('Country', 'UserProject_natioanlity_id'); ?>
    <?php echo $form->dropDownList($userProjectModel, 'nationality_id',
            CHtml::listData(ProjectNationality::model()->getActiveByProjectId($userProjectModel->project_id), 'nationality.id', 'nationality.country'), array('empty'=>'select Type')); ?>
    <?php echo $form->error($userProjectModel,'nationality_id'); ?>
    </fieldset>

    <fieldset>

    <legend>Information</legend>

    <?php echo $form->textFieldRow($model,'firstname_en',array('class'=>'span5','maxlength'=>200)); ?>

    <?php echo $form->textFieldRow($model,'lastname_en',array('class'=>'span5','maxlength'=>200)); ?>

    <?php echo $form->textFieldRow($model,'firstname_th',array('class'=>'span5','maxlength'=>200)); ?>

    <?php echo $form->textFieldRow($model,'lastname_th',array('class'=>'span5','maxlength'=>200)); ?>

    <?php echo $form->textFieldRow($model,'nickname',array('class'=>'span5','maxlength'=>30)); ?>

    <?php echo $form->textFieldRow($model,'username',array('class'=>'span5','maxlength'=>60)); ?>

    <?php echo $form->passwordFieldRow($model,'password',array('class'=>'span5','maxlength'=>45)); ?>

    <?php echo $form->passwordFieldRow($model,'rePassword',array('class'=>'span5','maxlength'=>45)); ?>

    <?php echo CHtml::label('Birth Date', 'User_birth_date'); ?>
    <?php
        $this->widget('zii.widgets.jui.CJuiDatePicker', array(
            'model' => $model,
            'attribute' => 'birth_date',
            'options' => array(
                'dateFormat' => 'dd-mm-yy',
                'showOtherMonths' => true,
                'selectOtherMonths' => true,
                'changeYear' => true,
                'changeMonth' => true,
                'yearRange' => '1950:'.date('Y'),
            ),
        ));
    ?>
    <?php echo $form->error($model,'birth_date'); ?>
    <?php echo $form->textFieldRow($model,'mobile_phone',array('class'=>'span5','maxlength'=>45)); ?>

    <?php
        echo $form->dropDownListRow($model, 'religion_id',
        CHtml::listData(Religion::model()->getAllActive(), 'id', 'name'),
        array('empty'=>'select Type'));
    ?>

    <?php echo $form->dropDownListRow($model,'gender', array('M' => 'Male', 'F' => 'Female')); ?>

    <?php echo $form->textFieldRow($model,'id_card',array('class'=>'span5','maxlength'=>200)); ?>

    <?php echo $form->textFieldRow($model,'passport_no',array('class'=>'span5','maxlength'=>10)); ?>

    <?php echo $form->dropDownListRow($model, 'nationality_id', CHtml::listData(Nationality::model()->getAllActive(), 'id', 'nationality'), array('empty'=>'select Type')); ?>

    </fieldset>

    <fieldset>

    <legend>Address</legend>

    <?php echo $form->textFieldRow($userAddressModel,'address_no',array('class'=>'span5','maxlength'=>45)); ?>

    <?php echo $form->textFieldRow($userAddressModel,'village',array('class'=>'span5','maxlength'=>100)); ?>

    <?php echo $form->textFieldRow($userAddressModel,'soi',array('class'=>'span5','maxlength'=>100)); ?>

    <?php echo $form->textFieldRow($userAddressModel,'street',array('class'=>'span5','maxlength'=>100)); ?>

    <?php echo $form->textFieldRow($userAddressModel,'sub_district',array('class'=>'span5','maxlength'=>100)); ?>


    <?php echo CHtml::label('Country', 'UserAddress_natioanlity_id'); ?>
    <?php echo $form->dropDownList($userAddressModel, 'nationality_id',
    CHtml::listData(Nationality::model()->getAllActive(), 'id', 'country'), array(
    'ajax' => array(
      'type'=>'POST',
      'url'=>CController::createUrl(Yii::app()->language . '/province/getOptionByNationalityId/'),
                'update'=>'#UserAddress_province_id',
              'data'=>array('nationalityId'=>'js:this.value'),
     ))); ?>
    <?php echo $form->error($model,'nationality_id'); ?>


    <?php echo $form->dropDownListRow($userAddressModel, 'province_id',
        CHtml::listData(Province::model()->getByNationalityId($userAddressModel->nationality_id), 'id', 'name'),
            array(
                'empty'=>'-- select Type --',
                'ajax' => array(
                      'type'=>'POST',
                      'url'=>CController::createUrl(Yii::app()->language . '/district/getOptionByProvinceId/'),
                      'update'=>'#UserAddress_district_id',
                      'data'=>array('provinceId'=>'js:this.value'),
         ))); ?>
    <?php echo $form->dropDownListRow($userAddressModel,'district_id'); ?>

    <?php echo $form->textFieldRow($userAddressModel,'zipcode',array('class'=>'span5','maxlength'=>5)); ?>

    </fieldset>

    <fieldset>

    <legend>Education Background</legend>

    <?php echo $form->dropDownListRow($userEducationModel, 'education_type_id',
      CHtml::listData(EducationType::model()->findAll(), 'id', 'name'), array(
        'empty'=>'select Type',
        'ajax' => array(
          'type'=>'POST',
          'url'=>CController::createUrl(Yii::app()->language . '/school/dynamicData'),
                    'update'=>'#UserEducation_school_id',
         ))); ?>

    <?php echo $form->dropDownListRow($userEducationModel,'school_id'); ?>

    <?php echo $form->textFieldRow($userEducationModel,'other_school_name',array('class'=>'span5','maxlength'=>200, 'disabled' => 'disabled')); ?>

    <?php echo $form->textFieldRow($userEducationModel,'faculty',array('class'=>'span5')); ?>

    <?php echo $form->textFieldRow($userEducationModel,'year',array('class'=>'span5')); ?>

    <?php echo $form->textFieldRow($userEducationModel,'gpa',array('class'=>'span5','maxlength'=>4)); ?>
    </fieldset>

    <div class="form-actions">
        <?php $this->widget('bootstrap.widgets.TbButton', array(
            'buttonType'=>'submit',
            'type'=>'primary',
            'label'=>$model->isNewRecord ? 'Create' : 'Save',
        )); ?>
    </div>

<?php $this->endWidget(); ?>
